/*
 * @Author: your name
 * @Date: 2021-06-08 12:01:00
 * @LastEditTime: 2021-06-16 11:17:46
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \UDP\SERVER_\database.h
 */
#pragma once
#include<stdio.h>
#include<iostream>
#include "sqlite3.h"
#include "case.h"
#include<string.h>
#include<string>

#include "dealstr.h"

using namespace std;

#define SQL_NAME "data.db" //数据库名称
#define SQL_MAX_LENGTH 100 //数据库语句最大长度

class Database
{
private:
    sqlite3 *db;
    char *zErrMsg = 0;
    int rc;
    char** pResult;
    int nRow;
    int nCol;
public:
    //构造函数，连接数据库
    Database();
    //析构函数，释放连接
    ~Database();
    //执行数据库语句
    bool query_SQL(char* sql_str);
    //展示table
    bool show_Table(char* table);
    //查询表中是否有待查数据
    bool query_Table(char* sql);
    //登录验证
    int verify_User_Passwd(char* sql_str,info& s_info);
    //查询商品数据
    int get_All_Commodity_Info(info& s_info);
    //重载get_All_Commodity_Info,提供给具体SQL语句进行检索
    int get_All_Commodity_Info(info& s_info,char* sql);
    //获取用户余额
    double get_User_Balance(const string& name);
    //给定id获取商品信息
    bool get_Com_Info(int iden,commodity& com);
};